//
//  CheckSafeDetailVC.m
//  RoadMaintain
//
//  Created by 岳学坤 on 2017/3/18.
//  Copyright © 2017年 岳学坤. All rights reserved.
//

#import "CheckSafeDetailVC.h"
#import "PutNormolForIPhoneCell.h"
#import "SearchForDiseaseAddPicsForIPhoneCell.h"
#import "SearchForDiseaseForIPhoneCell.h"
#import "MoreBtnForIphoneCell.h"
#define PutCellID @"cellid1"
#define PicCellID @"cellid2"
#define DetailCellID @"cellid3"
#define MoreBtnCellID @"cellid4"
@interface CheckSafeDetailVC ()<DetailForIPhoneCellDelegate,MoreBtnForIPhoneCellDelegate,PicsForIPhoneDelegate,UIAlertViewDelegate>
{
    NSString * _status;//0 保存  1  上报
}
@property (nonatomic,strong) NSDictionary *dic;//获取的需要展示的ID字典
@property (nonatomic,strong) UIView *footerView;
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *contentArray;
@property (nonatomic,strong) NSMutableArray *safeListArray;

@property (nonatomic,strong) NSMutableArray *routeArray;
@property (nonatomic,strong) NSString *routeId;
@property (nonatomic,strong) NSString *routeName;
@property (nonatomic,strong) NSString *elseThing;
@property (nonatomic,strong) NSString *idea;
@property (nonatomic,strong) NSMutableArray *imgArray;
@property (nonatomic,strong) NSString *detail;
@property (nonatomic,strong) NSString *checkTime;
@property (nonatomic,strong) NSString *checkerName;
@property (nonatomic,strong) NSString *checkerId;
@property (nonatomic,strong) NSString *safetyUserName;
@property (nonatomic,strong) NSString *safetyUserId;
@property (nonatomic,strong) NSString *doInfo;

@property (nonatomic,strong) NSMutableArray * deleteArray;//删除的图片数组

@end

@implementation CheckSafeDetailVC

#pragma mark - Life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self resetNav];
    [self setWebData];
    [self setTableViewFooterView];
}
#pragma mark - Property
- (NSArray *)titleArray{
    if (_titleArray==nil) {
        _titleArray = @[@[@"安全检查编码",@"路线编码",@"通知单编码"],@[@"其他情况"],@[@"对出现安全隐患处理意见(必填)"],@[@"施工项目内容(必填)"],@[@"检查人",@"检查日期",@"安全管理员",@"安全员签字日期",@"巡查日期"],@[@"现场安全措施照片"],@[@"备注"]];
    }
    return _titleArray;
}
- (NSArray *)contentArray{
    if (_contentArray==nil) {
        _contentArray = @[@[@"",@"",@""],@[@"请描述其他情况"],@[@"请填写您的处理意见"],@[@"请填写具体施工内容"],@[@"",@"",@"",@"",@""],@[@""],@[@"请填写备注内容"]];
    }
    return _contentArray;
}
- (NSArray *)safeListArray{
    if (_safeListArray==nil) {
        _safeListArray = [[NSMutableArray alloc]initWithCapacity:1];
        [_safeListArray addObjectsFromArray:@[@"0",@"0",@"0",@"0",@"0",@"0"]];
    }
    return _safeListArray;
}
- (NSMutableArray *)imgArray{
    if (_imgArray==nil) {
        _imgArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _imgArray;
}
- (NSMutableArray *)routeArray{
    if (_routeArray == nil) {
        _routeArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _routeArray;
}
- (NSMutableArray *)deleteArray{
    if (_deleteArray == nil) {
        _deleteArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _deleteArray;
}
#pragma mark - UI
- (void)resetNav{
    [self setTheBackBtn];
    self.myTitle.text = @"安全检查";
    [self.tableView registerClass:[PutNormolForIPhoneCell class] forCellReuseIdentifier:PutCellID];
    [self.tableView registerClass:[SearchForDiseaseAddPicsForIPhoneCell class] forCellReuseIdentifier:PicCellID];
    [self.tableView registerClass:[SearchForDiseaseForIPhoneCell class] forCellReuseIdentifier:DetailCellID];
    [self.tableView registerClass:[MoreBtnForIphoneCell class] forCellReuseIdentifier:MoreBtnCellID];
    
}
- (void)setTableViewFooterView{
    
    self.footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 200*WidthRate)];
    self.footerView.backgroundColor = [PublicMethod colorWithHexString:@"#eaeaea" andAlpha:1];
    self.tableView.tableFooterView = self.footerView;
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.layer.cornerRadius = 5;
    saveBtn.layer.masksToBounds = YES;
    saveBtn.layer.borderColor = [MAIN_Color CGColor];
    saveBtn.layer.borderWidth = 1;
    saveBtn.backgroundColor = Bai_Color;
    [saveBtn setTitleColor:MAIN_Color forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:17*ZitiRate];
    [self.footerView addSubview:saveBtn];
    [saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-120*WidthRate);
        make.height.mas_equalTo(42*WidthRate);
        make.left.mas_equalTo(22*WidthRate);
        make.right.equalTo(self.footerView.mas_centerX).offset(-15*WidthRate);
    }];
    
    
    UIButton *submit = [UIButton buttonWithType:UIButtonTypeCustom];
    submit.layer.cornerRadius = 5;
    submit.layer.masksToBounds = YES;
    submit.backgroundColor = MAIN_Color;
    [submit setTitleColor:Bai_Color forState:UIControlStateNormal];
    [submit setTitle:@"上报" forState:UIControlStateNormal];
    [submit addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    submit.titleLabel.font = [UIFont systemFontOfSize:17*ZitiRate];
    [self.footerView addSubview:submit];
    [submit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-120*WidthRate);
        make.height.mas_equalTo(42*WidthRate);
        make.right.mas_equalTo(-22*WidthRate);
        make.left.equalTo(self.footerView.mas_centerX).offset(15*WidthRate);
    }];
    if (self.state) {
        self.tableView.tableFooterView.hidden = YES;
    }else{
        self.tableView.tableFooterView.hidden = NO;
    }
}

#pragma mark - UI Response
- (void)save{
    _status = @"0";
    [self putData];
}
- (void)submit{
    _status = @"1";
    [self putData];
}
- (void)putData{
    
    
    if ([self.routeId length]==0) {
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"路线编码不能为空。" animated:YES];
    }else if ([self.idea length]==0) {
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"对出现安全隐患处理意见不能为空。" animated:YES];
    }else if ([self.doInfo length]==0) {
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"施工项目内容不能为空。" animated:YES];
    }else{
        if ([_status integerValue]==1) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"上报" message:@"确定上报此安全检查单吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
            
        }else{
            [self endPutData];
        }
        
    }
    
}
- (void)endPutData{
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    NSMutableArray * addImgArray = [[NSMutableArray alloc]initWithCapacity:1];
    for (int i = 0; i<self.imgArray.count; i++) {
        if ([self.imgArray[i] isKindOfClass:[UIImage class]]) {
            [addImgArray addObject:self.imgArray[i]];
        }
    }
    
    [NetWorkTool putUpSafetyCheck:self.dic[@"securityCheckId"] isSignCorrect:self.safeListArray[0] isSaftycoat:self.safeListArray[1] ifSafetyProcess:self.safeListArray[2] isSafetyTraffic:self.safeListArray[3] isSafeGuard:self.safeListArray[4] isExistedSafetyman:self.safeListArray[5] otherContent:self.elseThing dealSuggestion:self.idea content:self.doInfo checkerUser:self.checkerId checkerDate:self.dic[@"checkDate"] safetyManager:self.safetyUserId signDate:self.checkTime  remark:self.detail routeId:self.routeId state:_status block:^(id data) {
       
        if (data) {
            if ([data[@"success"]integerValue]) {
                
                [NetWorkTool userHeadImg:addImgArray deleteArr:self.deleteArray billId:self.dic[@"securityCheckId"] billType:@"dmSecurityCheck" success:^(NSDictionary *responseObject) {
                     [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                    if ([_status integerValue]==0) {
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"保存成功" animated:YES];
                    }else{
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"上报成功" animated:YES];
                    }
                    [self performSelector:@selector(pop) withObject:nil afterDelay:1];
                } failure:^(NSError *error) {
                    [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，操作失败。" animated:YES];
                } uploadProgressBlock:^(float uploadPercent, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
                    
                }];
                
            }else{
                 [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }            }
        }else{
            [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，操作失败。" animated:YES];
        }
    }];
    
}

- (void)pop{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Data handle
- (void)setWebData{
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    [NetWorkTool safetyCheckDetailWithID:self.codeId block:^(id data) {
       [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];        if (data) {
            if ([data[@"success"] integerValue]) {
                self.dic = data[@"data"][@"DmSecurityCheckList"];
                self.routeName = self.dic[@"routeCode"];
                self.routeId = self.dic[@"routeId"];
                [self.routeArray removeAllObjects];
                [self.routeArray addObjectsFromArray:data[@"data"][@"BdRouteList"]];
                
                self.detail = self.dic[@"remark"];
                self.elseThing = self.dic[@"otherContent"];
                self.idea = self.dic[@"dealSuggestion"];
                self.doInfo = self.dic[@"content"];
                self.safetyUserId = self.dic[@"safetyManager"];
                self.safetyUserName = self.dic[@"safetyManagerName"];
                self.checkerName = self.dic[@"checkerUserName"];
                self.checkerId = self.dic[@"checkerUser"];
                self.checkTime = self.dic[@"signDate"];
                
                [self.imgArray removeAllObjects];
                if ([self.dic[@"filePath"] length]==0) {
                    
                }else{
                    [self.imgArray addObjectsFromArray: [self.dic[@"filePath"] componentsSeparatedByString:@","]];
                }

                [self.safeListArray replaceObjectAtIndex:0 withObject:self.dic[@"isSignCorrect"]];
                [self.safeListArray replaceObjectAtIndex:1 withObject:self.dic[@"isSaftycoat"]];
                [self.safeListArray replaceObjectAtIndex:2 withObject:self.dic[@"ifSafetyProcess"]];
                [self.safeListArray replaceObjectAtIndex:3 withObject:self.dic[@"isSafetyTraffic"]];
                [self.safeListArray replaceObjectAtIndex:4 withObject:self.dic[@"isSafeGuard"]];
                [self.safeListArray replaceObjectAtIndex:5 withObject:self.dic[@"isExistedSafetyman"]];
                
                [self.tableView reloadData];
            }else{
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }
            }
        }else{
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES];
        }
    }];
}
- (void)gotoLogin{
    [PublicMethod noTokenToLoginWithNav:self.navigationController];
}

#pragma mark - Delegate
- (void)detailForIPhoneCellWithString:(NSString *)str indexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==1) {
        self.elseThing = str;
    }else if (indexPath.section==2){
        self.idea = str;
    }else if (indexPath.section==3){
        self.doInfo = str;
    }else{
        self.detail= str;
    }
}
- (void)picsForIphoneWithImgArray:(NSMutableArray *)arr AndDeleteArray:(NSMutableArray *)deleteArray{
    [self.imgArray removeAllObjects];
    [self.imgArray addObjectsFromArray:arr];
    [self.deleteArray removeAllObjects];
    [self.deleteArray addObjectsFromArray:deleteArray];
    
}
- (void)moreBtnForIPhoneCellWithArray:(NSMutableArray *)arr{
    [self.safeListArray removeAllObjects];
    [self.safeListArray addObjectsFromArray:arr];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if ([self.imgArray count]==0&&self.state==1) {
        return 6;
    }else{
        return 7;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 3;
            break;
        case 1:
            return 1;
            break;
        case 2:
            return 1;
            break;
        case 3:
            return 1;
            break;
        case 4:
            return 5;
            break;
        case 5:
            return 1;
            break;
        default:
            return 1;
            break;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
        {
             if(indexPath.row==2){
                return 170*WidthRate;
            }else{
                return  45*WidthRate;
            }
        }
            break;
        case 1:
        {
            return 100*WidthRate;
        }
            break;
        case 2:
        {
            return 100*WidthRate;
        }
            break;
        case 3:
        {
            return 100*WidthRate;
        }
            break;
        case 4:
        {
            return 45*WidthRate;
        }
            break;
        case 5:
        {
            return 135*WidthRate;
        }
            break;
        default:{
            return 135*WidthRate;
        }
            break;
    }
    
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.state!=1) {
        if (indexPath.row==0&&indexPath.section==4) {
            [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
            [NetWorkTool receiveManWithUnitID:nil block:^(id data) {
                [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                if (data) {
                    if([data[@"success"] integerValue]){
                        UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"检查人" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                        for (int i = 0; i<[data[@"data"] count]; i++) {
                            [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"userName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                self.checkerName = data[@"data"][i][@"userName"];
                                self.checkerId = data[@"data"][i][@"userId"];
                                PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                                cell.contentLab.text = self.checkerName;
                                
                            }]];
                        }
                        [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [self presentViewController:actionSheet animated:YES completion:nil];
                        });
                        
                    }else{
                        [PublicMethod noTokenToLoginWithNav:self.navigationController];
                    }
                    
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取检查人失败" animated:YES];
                }
                
            }];
            
        }

        if (indexPath.row==2&&indexPath.section==4) {
            [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
            [NetWorkTool receiveManWithUnitID:nil block:^(id data) {
                [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                if (data) {
                    if([data[@"success"] integerValue]){
                        UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"安全管理员" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                        for (int i = 0; i<[data[@"data"] count]; i++) {
                            [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"userName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                self.safetyUserName = data[@"data"][i][@"userName"];
                                self.safetyUserId = data[@"data"][i][@"userId"];
                                PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                                cell.contentLab.text = self.safetyUserName;
                                
                            }]];
                        }
                        [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [self presentViewController:actionSheet animated:YES completion:nil];
                        });
                        
                    }else{
                        [PublicMethod noTokenToLoginWithNav:self.navigationController];
                    }
                    
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取安全管理员失败" animated:YES];
                }
                
            }];

        }
        if (indexPath.row==3&&indexPath.section==4) {
            //x,y 值无效，默认是居中的
            KSDatePicker* picker = [[KSDatePicker alloc] initWithFrame:CGRectMake(0, 0, 280, 260)];
            
            //配置中心，详情见KSDatePikcerApperance
            
            picker.appearance.radius = 5;
            
            //设置回调
            picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){
                
                if (buttonType == KSDatePickerButtonCommit) {
                    
                    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
                    [formatter setDateFormat:@"yyyy-MM-dd"];
                    self.checkTime = [formatter stringFromDate:currentDate];
                    PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                    cell.contentLab.text = self.checkTime;
                }
            };
            // 显示
            [picker show];
        }
    }

    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0||indexPath.section == 4) {
        if (indexPath.section==0&&indexPath.row==2) {
            MoreBtnForIphoneCell *cell = [tableView dequeueReusableCellWithIdentifier:MoreBtnCellID];
            cell.delegate = self;
            cell.state = self.state;
            cell.titleLab.text = self.titleArray[indexPath.section][indexPath.row];
            cell.contentLab.text = self.dic[@"maintentanceNoticeNo"];
            [cell addValue:self.safeListArray];
            return cell;
        }else{
        PutNormolForIPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:PutCellID];
        cell.titleLab.text = self.titleArray[indexPath.section][indexPath.row];
            if (indexPath.section==0&&indexPath.row==0) {
                cell.contentLab.text = self.dic[@"billNo"];
            }else if (indexPath.section==0&&indexPath.row==1){
                cell.contentLab.text = self.routeName;
            }else if (indexPath.section==4&&indexPath.row==0){
                cell.contentLab.text = self.checkerName;
            }else if (indexPath.section==4&&indexPath.row==1){
                cell.contentLab.text = self.dic[@"checkDate"];
            }else if (indexPath.section==4&&indexPath.row==2){
                cell.contentLab.text = self.safetyUserName;
            }else if (indexPath.section==4&&indexPath.row==3){
                cell.contentLab.text = self.checkTime;
                [cell.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(10*WidthRate);
                    make.top.mas_equalTo(0);
                    make.bottom.mas_equalTo(0);
                    make.width.mas_equalTo(130*WidthRate);
                }];
            }else if (indexPath.section==4&&indexPath.row==4){
                cell.contentLab.text = self.dic[@"inspectionDate"];
            }
    
            if (self.state==1) {
            cell.img.hidden = YES;
            }else{
        if ((indexPath.row==0&&indexPath.section==4)||(indexPath.row==2&&indexPath.section==4)||(indexPath.row==3&&indexPath.section==4)) {
            cell.img.hidden = NO;
            cell.img.image = [UIImage imageNamed:@"enter"];
        }else {
            cell.img.hidden = YES;
        }
            }
        return  cell;
        }
    } else if(indexPath.section==1||indexPath.section==2||indexPath.section==3||indexPath.section==6){
        SearchForDiseaseForIPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailCellID];
        cell.delegate = self;
        cell.indexPath = indexPath;
        cell.titleLab.text = self.titleArray[indexPath.section][indexPath.row];
        cell.detailTextView.placeholder = self.contentArray[indexPath.section][indexPath.row];
        if (self.state == 1) {
            cell.detailTextView.editable = NO;
            if (indexPath.section==6) {
                if ([self.detail length]==0) {
                    cell.detailTextView.text = @"";
                    cell.detailTextView.placeholder = @"请填写备注内容";
                }else{
                cell.detailTextView.text= self.detail;
            }
            }
            if (indexPath.section==3) {
                if ([self.doInfo length]==0) {
                    cell.detailTextView.text = @" ";
                }else{
                    cell.detailTextView.text= self.doInfo;
                }
            }
            if (indexPath.section==1) {
                if ([self.elseThing length]==0) {
                    cell.detailTextView.text = @" ";
                }else{
                    cell.detailTextView.text= self.elseThing;
                }
            }
            if (indexPath.section==2) {
                if ([self.idea length]==0) {
                    cell.detailTextView.text = @" ";
                }else{
                    cell.detailTextView.text= self.idea;
                }
            }
            
        }else{
            cell.detailTextView.editable = YES;
            if (indexPath.section==1) {
                cell.detailTextView.text = self.elseThing;
            }else if (indexPath.section ==2){
                cell.detailTextView.text = self.idea;
            }else if (indexPath.section ==6){
                cell.detailTextView.text = self.detail;
            }else{
                cell.detailTextView.text = self.doInfo;
            }
        }
       
        return  cell;
        
    }else{
        if ([self.imgArray count]==0&&self.state==1) {
            SearchForDiseaseForIPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailCellID];
            cell.delegate = self;
            cell.indexPath = indexPath;
            cell.titleLab.text = @"备注";
            if (self.state == 1) {
                cell.detailTextView.editable = NO;
                if ([self.detail length]==0) {
                    cell.detailTextView.text = @" ";
                }else{
                    cell.detailTextView.text= self.detail;
                }
            }else{
                cell.detailTextView.editable = YES;
                cell.detailTextView.placeholder = @"请输入备注内容";
                cell.detailTextView.text = self.detail;
            }
            return  cell;
        }else{
            SearchForDiseaseAddPicsForIPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:PicCellID];
            cell.titleLab.text = @"现场安全措施照片";
            cell.delegate = self;
            if (self.state==1) {
                cell.isReset = NO;
            }else{
                cell.isReset = YES;
            }
            cell.con = self;
            [cell addValue:self.imgArray];

            return  cell;
        }
      
    }
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex) {
        [self endPutData];
    }
}
@end
